package com.sino.operation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sino.operation.dto.inner.CenterDto;
import com.sino.operation.entity.SysCenter;
import com.sino.operation.entity.SysTeller;
import com.sino.operation.mapper.SysCenterMapper;
import com.sino.operation.service.SysCenterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 中心表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-10-07
 */
@Service
public class SysCenterServiceImpl extends ServiceImpl<SysCenterMapper, SysCenter> implements SysCenterService {

    @Autowired(required = false)
    private SysCenterMapper sysCenterMapper;
    @Override
    public IPage<SysCenter> selectList(Map<String, String> map) {
        QueryWrapper<SysCenter> wrapper = new QueryWrapper<>();
        int current= Integer.parseInt(map.get("current"));
        int size= Integer.parseInt(map.get("size"));
        return   sysCenterMapper.selectPage(new Page<>(current, size), wrapper);
    }

    @Override
    public SysCenter selectCenterByOrgNo(String orgNo) {
        return sysCenterMapper.selectCenterByOrgNo(orgNo);
    }

    @Override
    public List<CenterDto> findCenter() {
        List<SysCenter> centerList = sysCenterMapper.findCenter();
        ArrayList<CenterDto> centerDtos = new ArrayList<>();
        centerList.forEach(sysCenter -> {
            CenterDto centerDto = new CenterDto();
            centerDto.setCenterNo(sysCenter.getCenterNo());
            centerDto.setCenterName(sysCenter.getCenterName());
            centerDtos.add(centerDto);
        });
        return centerDtos;
    }
}
